package com.clever.mall.controller;

import com.clever.mall.commons.dto.AddressDto;
import com.clever.mall.commons.result.BaseResult;
import com.clever.mall.service.AddressService;
import com.clever.mall.vo.AddressVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: project-item
 * @author: hzx
 * @since: JDK 1.8
 * @create: 2020-11-10 17:22
 **/
@RestController
@RequestMapping("/address")
public class AddressController {

    @Resource
    AddressService service;

    /**
     * 通过用户id获取所有用户地址信息
     * @param uid
     * @return
     */
    @GetMapping("/all")
    public BaseResult<List<AddressVo>> allAddress(int uid) {
        return BaseResult.success(service.selectAddressAll(uid));
    }

    /**
     * 通过地址id获取地址信息
     * @param aid
     * @return
     */
    @GetMapping("/id")
    public BaseResult<AddressVo> getAddress(int aid) {
        return BaseResult.success(service.selectAddressById(aid));
    }

    /**
     * 添加地址
     * @param addressDto
     * @return
     */
    @PostMapping("add")
    public BaseResult<Integer> insertAddress(@RequestBody AddressDto addressDto) {
        return BaseResult.success(service.insertAddress(addressDto));
    }

    /**
     * 修改地址
     * @param addressDto
     * @return
     */
    @PostMapping("update")
    public BaseResult<Integer> updateAddress(@RequestBody AddressDto addressDto) {
        return BaseResult.success(service.updateAddress(addressDto));
    }

    /**
     * 删除地址
     * @param uid
     * @param aid
     * @return
     */
    @PostMapping("del")
    public BaseResult<Integer> delAddress(int uid, int aid) {
        return BaseResult.success(service.delAddress(uid, aid));
    }

}
